<template>
    <div>
        <fullscreenModal :modal="fullscreenModal" :isAdd="false" defaultBgColor="#eee" label="拜访" :isShowEdit="false" editType="detail" @handleClose="fullscreenModal = false">
            <div class="detailCon">
                <div class="basicBox" v-show="!fullLoading">
                    <div class="imgBox">
                        <img :src="imgSrc || 'images/convaccess/people.svg'" @click="handleView(imgSrc)">
                    </div>
                    <div class="top">
                        <p class="status">
                            <img v-if="visitorInfo.appStatus === '2'" src="images/convaccess/qrcode.svg" @click="$refs.codeViewRef.getData(visitorInfo.visitorsId);">
                            <span v-else>{{visitorInfo.appStatusName}}</span>
                        </p>
                        <div class="tit">
                            <b>
                                {{visitorInfo.interviewer}}
                            </b>
                            <a v-if="visitorInfo.visitType === '01'" class="type">登记</a>
                            <a v-if="visitorInfo.visitType === '02'" class="type">预约</a>
                        </div>
                        <div class="row">
                            {{visitorInfo.visitReasonName}}拜访
                        </div>
                        <div class="row">
                            {{visitorInfo.interviewerCorpName}}
                            <span v-if="followerList.length">（{{followerList.length + 1}}人）</span>
                        </div>
                    </div>
                    <div class="middle">
                        <p>
                            <label>拜访时间</label>
                            <span>{{visitorInfo.visitTime}}</span>
                        </p>
                        <p>
                            <label>离开时间</label>
                            <span>{{visitorInfo.departureTime}}</span>
                        </p>
                        <p>
                            <label>车牌号</label>
                            <span>{{visitorInfo.plateNumber}}</span>
                        </p>
                    </div>
                    <div class="bottom">
                        <p>
                            <label>{{visitorInfo.visitType === '01' ? '登记' : '预约'}}时间</label>
                            <span>{{visitorInfo.createTime}}</span>
                        </p>
                    </div>
                </div>
                <div class="followerBox">
                    <h5 @click="isFold = !isFold">
                        <b>随行人员信息（{{followerList.length}}人）</b>
                        <p v-if="isFold">展开 <van-icon name="arrow-down" /></p>
                        <p v-else>折叠 <van-icon name="arrow-up" /></p>
                    </h5>
                    <div v-show="!isFold" class="list">
                        <div v-for="(val, ind) in followerList" :key=ind class="list-item">
                            <img :src="(val.visitorPic && fileUrlObj[val.visitorPic]) ? fileUrlObj[val.visitorPic] : 'images/convaccess/people.svg'" @click="handleView(fileUrlObj[val.visitorPic])">
                            <div class="right">
                                <div>
                                    <label>姓名：</label>
                                    <p>{{val.follower || "-"}}{{val.followerSexName ? ('（' + val.followerSexName + '）') : ''}}</p>
                                </div>
                                <div>
                                    <label>手机号码：</label>
                                    <p>{{$infoHiding.handlePhone(val.followerPhone) || "-"}}</p>
                                </div>
                                <div>
                                    <label>{{val.visitorCertTypeName}}：</label>
                                    <p>{{(val.visitorCertType === '1' ? $infoHiding.handleIdCard(val.visitorCertNo) : val.visitorCertNo) || "-"}}</p>
                                </div>
                                <div>
                                    <label>来访单位：</label>
                                    <p>{{val.visitorCorpName || "-"}}</p>
                                </div>
                            </div>
                        </div>
                        <van-empty v-if="!followerList.length" class="custom-image" :image="require('../../../../assets/images/empty.png')" description="暂无随行人员" />
                    </div>
                </div>
            </div>
        </fullscreenModal>
        <codeView ref="codeViewRef" title="预约码" />
        <full-loading v-if="fullLoading"></full-loading>
    </div>
</template>

<script>
    import { queryFileList } from '@/api/common';
    import { getById } from '@/api/srvAssurance/convaccess/appointmentVisit';
    import { ImagePreview } from 'vant';
    import codeView from '../accessRecord/codeView.vue';

    export default {
        components: { codeView },
        data () {
            return {
                fullscreenModal: false,
                fullLoading: false,
                isFold: true,
                followerList: [],
                fileUrlObj: {},
                visitorInfo: {
                    visitorsId: '',
                    interviewer: '',
                    visitorSexName: '',
                    interviewerCorpName: '',
                    visitType: '',
                    visitTime: '',
                    departureTime: '',
                    plateNumber: '',
                    visitReasonName: '',
                    appStatus: '',
                    appStatusName: '',
                    createTime: ''
                },
                imgSrc: ''
            };
        },
        methods: {
            // 查看详情
            handleDetail (item) {
                this.queryPhotoFileInfoData(item.fileCode);
                for (var key in this.visitorInfo) {
                    this.visitorInfo[key] = '';
                }
                this.followerList = [];
                this.fullscreenModal = true;
                this.fullLoading = true;
                this.isFold = true;
                let filecodeArr = [];
                getById(item.visitorsId).then(res => {
                    if (res.code === 1000 && res.data) {
                        for (var key in this.visitorInfo) {
                            if (res.data[key]) {
                                this.visitorInfo[key] = res.data[key];
                            }
                        }
                        this.followerList = res.data.visitorsEntourageSaveList || [];
                        this.followerList.forEach(item => {
                            if (item.visitorPic && !this.fileUrlObj[item.visitorPic]) {
                                filecodeArr.push(item.visitorPic);
                            }
                        })
                        if (filecodeArr.length) {
                            this.queryFileInfoData(filecodeArr);
                        }
                    }
                    this.fullLoading = false;
                }).catch(() => {
                    this.fullLoading = true;
                })
            },
            // 获取图片信息
            queryFileInfoData (filecodeArr) {
                queryFileList(filecodeArr).then(res => {
                    if (res.code === 1000 && res.data) {
                        res.data.forEach(item => {
                            this.fileUrlObj[item.fileCode] = item.url;
                        })
                        this.$forceUpdate();
                    }
                })
            },
            // 获取头像信息
            queryPhotoFileInfoData (filecode) {
                this.imgSrc = '';
                if (!filecode) return;
                queryFileList([filecode]).then(res => {
                    if (res.code === 1000 && res.data && res.data.length) {
                        this.imgSrc = res.data[0].url;
                    }
                })
            },
            // 图片预览
            handleView (url) {
                if (!url) return;
                ImagePreview({
                    images: [url],
                    closeable: true,
                });
            }
        },
    };
</script>

<style scoped lang="less">
    .detailCon {
        padding: 12px;
        box-sizing: border-box;
    }
    .basicBox {
        padding: 35px 10px 10px;
        box-sizing: border-box;
        align-items: center;
        background: #fff;
        border-radius: 8px;
        margin: 35px 0 8px 0;
        position: relative;
        .top {
            border-bottom: 1px dashed #aaa;
            padding: 0 5px 10px;
            margin-bottom: 12px;
            position: relative;
            line-height: 22px;
            .tit {
                b {
                    font-size: 16px;
                    span {
                        font-size: 14px;
                    }
                }
                .type {
                    background: #f2a84e;
                    font-size: 9px;
                    color: #fff;
                    margin-left: 8px;
                    padding: 2px 3px;
                    border-radius: 3px;
                }
            }
            .row {
                color: #999;
                font-size: 13px;
            }
            .status {
                position: absolute;
                top: 0;
                right: 0;
                span {
                    color: #bbb;
                    font-size: 13px;
                }
                img {
                    width: 35px;
                    height: 35px;
                    margin-right: 10px;
                }
            }
        }
        .middle {
            padding: 0 5px 10px;
            box-sizing: border-box;
            border-bottom: 1px dashed #aaa;
        }
        p {
            display: flex;
            line-height: 28px;
            label {
                width: 75px;
                color: #999;
            }
            span {
                color: #333;
                flex: 1;
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
            }
        }
        .bottom {
            padding: 0 5px;
            box-sizing: border-box;
            margin-top: 10px;
            p span,
            p label {
                color: #999;
            }
        }
        .imgBox {
            width: 70px;
            height: 70px;
            border-radius: 50%;
            padding: 2px;
            box-sizing: border-box;
            position: absolute;
            top: -35px;
            left: 50%;
            transform: translateX(-50%);
            background: #fff;
            overflow: hidden;
            img {
                width: 100%;
                height: 100%;
                border-radius: 50%;
            }
        }
    }
    h5 {
        border-bottom: 1px solid #f1f1f2;
        line-height: 40px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0 15px;
        font-weight: normal;
        position: relative;
        b {
            font-size: 14px;
        }
        p {
            font-weight: normal;
            position: absolute;
            color: #888;
            right: 15px;
        }
    }
    .followerBox {
        background: #fff;
        border-radius: 8px;
        margin-top: 12px;
        /deep/.van-empty {
            padding: 20px 0;
            .van-empty__image {
                width: 50px;
                height: 50px;
            }
        }
        .list-item {
            display: flex;
            padding: 10px;
            box-sizing: border-box;
            align-items: center;
            img {
                width: 60px;
                height: 60px;
                margin-right: 10px;
            }
            .right {
                flex: 1;
                overflow: hidden;
                div {
                    display: flex;
                    line-height: 28px;
                    label {
                        width: 75px;
                        color: #999;
                    }
                    p {
                        color: #333;
                        flex: 1;
                        overflow: hidden;
                        text-overflow: ellipsis;
                        white-space: nowrap;
                    }
                }
            }
        }
    }
</style>